﻿// -----------------------------------------------------------------------
// <copyright file="MemoryRepositoryProvider.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
// -----------------------------------------------------------------------
#region Usings

using System;
using System.Collections.Generic;
using GateShift.Common.Repository.Configuration;
using GateShift.Common.Repository.Interfaces.Repositories.Base;
using GateShift.Common.Repository.Interfaces.Repositories.System;

#endregion

namespace GateShift.Servers.GameServer.CoreData
{
    /// <summary>
    /// Data provider for the memory repository system
    /// </summary>
    public class MemoryRepositoryProvider : RepositoryProviderBase
    {
        private static readonly Dictionary<Type, IRepository> _repositories;

        /// <summary>
        /// Initializes static members of the MemoryRepositoryProvider class
        /// </summary>
        static MemoryRepositoryProvider()
        {
            _repositories = new Dictionary<Type, IRepository>
                                {
                                    { typeof(IClientSessionRepository), default(IClientSessionRepository) }
                                };
        }

        /// <summary>
        /// Retrieves a repository for data related actions
        /// </summary>
        /// <typeparam name="T"> The <typeparamref name="T"/> based reference to the type of repository needed</typeparam>
        /// <returns> The <typeparamref name="T"/> repository available to use</returns>
        public override T GetRepository<T>()
        {
            return _repositories.ContainsKey(typeof(T)) ? (T)_repositories[typeof(T)] : default(T);
        }
    }
}
